package com.dmzc.sort;

//选择排序
public class SelectSort {
    public static void main(String[] args) {
        Node1[] node1s = new Node1[5];
        Node1 node1 = new Node1(5, 6);
        node1s[0] = node1;
        node1 = new Node1(5, 5);
        node1s[1] = node1;
        node1 = new Node1(1, 3);
        node1s[2] = node1;
        node1 = new Node1(3, 2);
        node1s[3] = node1;
        node1 = new Node1(2, 1);
        node1s[4] = node1;
        int j = selectSort(node1s);
        System.out.println(j);
        for (int i = 0; i < node1s.length; i++) {
            System.out.println(node1s[i]);
        }
    }

    public static int selectSort(Node1[] node1s) {
        int count = 0;
        if (node1s.length <= 1) return count;
        for (int i = 0; i < node1s.length-1 ; i++) {
            for (int j = i + 1; j < node1s.length; j++) {
                if (node1s[j].index > node1s[j -1].index) {
                    Node1 tmp = node1s[j];
                    node1s[j] = node1s[j - 1];
                    node1s[j - 1] = tmp;
                    count++;
                }
            }
            Node1 tmp = node1s[i];
            node1s[i] = node1s[node1s.length - 1];
            node1s[node1s.length - 1] = tmp;
        }
        return count;
    }

}
